package org.yang.snake.controller;

import org.yang.snake.model.SysUser;
import org.yang.snake.service.SysUserService;
import org.yang.snake.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

/**
 * 用户(SysUser)表控制层
 *
 * @author shichenyang
 * @since 2019-08-21 11:05:17
 */
@Controller
@RequestMapping("sysUser")
public class SysUserController {
   /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;

    @PreAuthorize("hasAuthority('sysUser')")
    @GetMapping("/index")
    public String index(){
        return "sysUser/index";
    }
    
    @PreAuthorize("hasAuthority('sysUser_add')")
    @GetMapping("/add")
    public String add(){
        return "sysUser/add";
    }

    @PreAuthorize("hasAuthority('sysUser_update')")
    @GetMapping("/update")
    public String update(){
        return "sysUser/update";
    }
    
    @PreAuthorize("hasAuthority('sysUser')")
    @GetMapping("/list")
    @ResponseBody
    public Result list(SysUser sysUser,Integer page,Integer limit){
        return sysUserService.listAll(sysUser,page,limit);
    }
    
    @PreAuthorize("hasAuthority('sysUser_add')")
    @PostMapping("/add")
    @ResponseBody
    public Result add(SysUser sysUser){
        return sysUserService.insert(sysUser);
    }
    
    @PreAuthorize("hasAuthority('sysUser_update')")
    @PostMapping("/update")
    @ResponseBody
    public Result update(SysUser sysUser){
        return sysUserService.update(sysUser);
    }

    @PreAuthorize("hasAuthority('sysUser_delete')")
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(Long id){
        return sysUserService.deleteById(id);
    }
}